﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace comm
{
    public partial class gridtest : Form
    {
        BLL.tbl_Sensor bsen = new BLL.tbl_Sensor();

        public gridtest()
        {
            InitializeComponent();
        }

        protected void gridviewbind()
        {
            //dataGridView1.Columns["CustomerID"].Visible = false;
            System.Windows.Forms.DataGridViewTextBoxColumn SensorAddress = new DataGridViewTextBoxColumn();
            SensorAddress.DataPropertyName = "SensorAddress";
            SensorAddress.HeaderText = "传感器地址";
            SensorAddress.Name = "SensorAddress";
            SensorAddress.Resizable = System.Windows.Forms.DataGridViewTriState.True;


            System.Windows.Forms.DataGridViewTextBoxColumn LastTemperature = new DataGridViewTextBoxColumn();
            LastTemperature.DataPropertyName = "LastTemperature";
            LastTemperature.HeaderText = "当前温度";
            LastTemperature.Name = "LastTemperature";
            LastTemperature.Resizable = System.Windows.Forms.DataGridViewTriState.True;


            System.Windows.Forms.DataGridViewTextBoxColumn LastHumidity = new DataGridViewTextBoxColumn();
            LastHumidity.DataPropertyName = "LastHumidity";
            LastHumidity.HeaderText = "当前湿度";
            LastHumidity.Name = "LastHumidity";
            LastHumidity.Resizable = System.Windows.Forms.DataGridViewTriState.True;

            System.Windows.Forms.DataGridViewTextBoxColumn LastUpdateTime = new DataGridViewTextBoxColumn();
            LastUpdateTime.DataPropertyName = "LastUpdateTime";
            LastUpdateTime.HeaderText = "时间";
            LastUpdateTime.Name = "LastUpdateTime";
            LastUpdateTime.Resizable = System.Windows.Forms.DataGridViewTriState.True;

            this.dataGridView1.DataSource = bsen.GetAllList(" status=0 ").Tables[0];
            this.dataGridView1.Columns.Clear();//一定要先绑定数据后再清除列
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { SensorAddress });
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { LastTemperature });
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { LastHumidity });
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { LastUpdateTime });

        }

        private void gridtest_Load(object sender, EventArgs e)
        {
            gridviewbind();
        }
    }
}
